require("dotenv").config();

const Koa = require("koa");
const app = new Koa();
const { koaBody } = require("koa-body");
const router = require("../router");
const errorHandler = require("./errorHandler");

// 允许所有域名的跨域请求
const cors = require("koa2-cors");

app.use(cors());

app.use(koaBody());
app.use(router.routes()).use(router.allowedMethods());
app.on("error", errorHandler);

app.listen(process.env.APP_PORT, () => {
  console.log(`server is running on http://localhost:${process.env.APP_PORT}`);
});
